home *** CD-ROM | disk | FTP | other *** search
- /* bt_block.c - block level stuff */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ; /* refers to index descriptor */
- /* for current function call */
- BLOCK *retrieve_block() ;
-
- int find_block(pe,pb,poff,comp_fun) /* look for a key in a block */
- ENTRY *pe ; /* contains the target key */
- BLOCK *pb ; /* look in this block */
- int *poff ; /* store offset where we stop */
- int (*comp_fun) () ; /* address of compare function */
- { /* returns the compare results */
- int i ; /* offset */
- int ret ; /* result of last comparison */
- ENTRY *p ;
-
- i = 0 ;
- while( i < pb->bend ) /* repeat until end of block */
- { p = ENT_ADR(pb,i) ; /* get entry address */
- /* compare to target key */
- ret = call(comp_fun)( pe , ENT_ADR(pb,i) ) ;
- if( ret <= 0 ) /* quit when the target is */
- break ; /* <= the current entry */
- i = next_entry(pb,i) ; /* move to next entry */
- }
- *poff = i ; /* store offset where we stopped */
- return ret ; /* result of last compare */
- }
-
-
- int ins_block(pb,pe,off) /* add an entry to block */
- BLOCK *pb ; /* the block */
- ENTRY *pe ; /* the entry to insert */
- int off ; /* the offset where we insert it */
- {
- int ne ;
-
- ne = ENT_SIZE(pe) ; /* how big is the new insert ? */
- /* move everything to end of block */
- moveup( pb,off,ne) ; /* make room for new entry */
- copy_entry(ENT_ADR(pb,off),pe) ; /* move it in */
- pb->bend = pb->bend + ne ; /* adjust block size */
- }
-
- int del_block(pb,off) /* remove an entry from a block */
- BLOCK *pb ; /* the block to work on */
- int off ; /* where to remove the entry */
- {
- int ne ;
-
- ne = _SIZE( ENT_ADR(pb,off) ) ; /* get entry size */
- movedown(pb,off,ne) ; /* move entries above curr. one down */
- pb->bend = pb->bend - ne ; /* adjust number of bytes */
- }
-
-
- int moveup(pb,off,n) /* move parts of a block upward */
- BLOCK *pb ; /* the block */
- int off ; /* place to start moveing */
- int n ; /* how far to move things */
- {
- ENTRY *p ;
- /* move entries */
- mover(ENT_ADR(pb,off+n), /* to here */
- ENT_ADR(pb,off) , /* from here */
- pb->bend - off) ; /* rest of block */
- }
-
-
- int movedown(pb,off,n) /* move parts of a block downward */
- BLOCK *pb ; /* the block */
- int off ; /* place to start moveing */
- int n ; /* how far down to move things */
- {
- ENTRY *p ;
-
- /* move entries */
- mover(ENT_ADR(pb,off) , /* to here */
- ENT_ADR(pb,off+n) , /* from here */
- pb->bend - (off+n)) ; /* rest of the block */
- }
-
- int combine(pl,pr) /* combine two blocks */
- BLOCK *pl ; /* address of left block */
- BLOCK *pr ; /* address of right block */
- {
- moveup(pr,0,pl->bend) ; /* make room for left block */
- /* move in left block contents */
- mover(ENT_ADR(pr,0),ENT_ADR(pl,0),pl->bend) ;
- pr->bend = pr->bend + pl->bend ; /* adjust block size */
- }
-
-
-